<?php

/**
 * Description of listAction
\* www.teuker.nl - mail@teuker.nl
 * 
 * @author francisc
 */

class listAction extends sfAction {

    public function execute($request) {
        $date = $request->getParameter('date');
        $restaurant_id = $this->getUser()->getAttribute('current_restaurant_id');

        if (null == $restaurant_id)
            return $this->setTemplate('listMinimal');
        
        $day_index = Util::decideDayIndex($date);
        $this->day_intervals = SqlEngine::getDayIntervalsInfo(array('day' => $day_index ,
                                                                    'restaurant_id' => $restaurant_id));

        /* get the reservations by day interval and by time */
        $reservations = array();
        foreach ($this->day_intervals as $interval) {
            /* get the times for the $interval */
            $times = SqlEngine::getReservationTimes(array('time_start' => $interval['time_start'],
                                                          'time_end' => $interval['time_end'],
                                                          'date' => $date,
                                                          'restaurant_id' => $restaurant_id));

            if (!empty($times)) {
                foreach ($times as $index => $time) {
                    $reservations[$interval['name']][$time['time']] = SqlEngine::getReservations(array('time' => $time['time'],
                                                                                                       'date' => $date,
                                                                                                       'not_deleted' => true));
                }
            }
        }

        $this->reservations = $reservations;
    }
}
